<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script type="text/javascript" src="vue.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .el-header, .el-footer {
            background-color: #B3C0D1;
            color: #333;
            text-align: center;
            line-height: 60px;

        }
        .el-aside {
            background-color: #D3DCE6;
            color: #333;
            text-align: center;
            line-height: 200px;
            height: 650px;
            width: 200px;
        }

        .el-main {
            margin: 0;
            padding: 0;
        }

        body > .el-container {
            margin-bottom: 40px;
        }

        .el-container:nth-child(5) .el-aside,
        .el-container:nth-child(6) .el-aside {
            line-height: 260px;
        }

        .el-container:nth-child(7) .el-aside {
            line-height: 320px;
        }
        .el-tabs__header{
            margin: 0;
        }

        .el-row {
            margin-bottom: 15px;
            margin-top: 15px;
        &:last-child {
             margin-bottom: 0;
         }
        }
        .el-col {
            border-radius: 4px;
        }
        .bg-purple-dark {
            background: #99a9bf;
        }
        .bg-purple {
            background: #b3c0d1;
            height: 40px;
            line-height: 40px;
            padding: 0px;
        }
        .bg-purple-light {
            background: #e5e9f2;
        }
        .grid-content {
            border-radius: 4px;
            min-height: 36px;
        }
        .row-bg {
            padding: 10px 0;
            background-color: #f9fafc;
        }
    </style>
</head>
<body>
<div id="app">
    <el-container>
        <el-header>
            <el-row :gutter="20">
                <el-col :span="4"><div class="grid-content bg-purple">
                    欢迎<span v-text="empInfo.ename" style="color: red"></span>进入后台系统
                </div></el-col>
                <el-col :span="16"><div class="grid-content bg-purple">
                    <h3>菜先生后台管理系统</h3>
                </div></el-col>
                <el-col :span="4"><div class="grid-content bg-purple">
                    <a href="/cai/sys/logout"><el-button icon="el-icon-switch-button" circle style="color: red;"></el-button></a>
                </div></el-col>
            </el-row>
        </el-header>
        <el-container>
            <el-aside width="200px">
                <el-menu>
                    <el-submenu v-for="(p,i) in empPers" :index="p.id">
                        <template slot="title"><i :class="p.icon"></i>{{p.pname}}</template>
                        <el-menu-item-group>
                            <el-menu-item @click="addTep(s)" v-for="(s,i) in p.subMenu" :index="s.id"><i :class="s.icon"></i>{{s.pname}}</el-menu-item>
                        </el-menu-item-group>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-main>
                <el-tabs v-model="editableTabsValue" type="card" closable @tab-remove="removeTab">
                    <el-tab-pane
                            v-for="(item,index) in editableTabs"
                            :key="item.id"
                            :label="item.pname"
                            :name="item.id">
                        <iframe :src="item.url" width="100% " height="600" style="border: 0;"></iframe>
                    </el-tab-pane>
                </el-tabs>
            </el-main>
        </el-container>
    </el-container>
</div>
<script>
    //获取用户信息和权限信息
    $.get(" /cai/sys/getInfo",function(backData){
        app.empInfo= backData.data.empInfo;
        app.empPers = backData.data.permission;
    });
    var app=new Vue({
        el:"#app",
        data:{
            empInfo:{},
            empPers:[],
            editableTabs:[
                {"id":0,"pname":"欢迎页","url":"/cai/hello.html"}
            ],
            editableTabsValue:"0"
        },
        methods:{
            addTep:function(a){
                if(app.editableTabs.indexOf(a)<0){
                    app.editableTabs.push(a);
                }
                app.editableTabsValue = a.id;
            },
            removeTab(targetName) {
                let tabs = app.editableTabs;
                let activeName = app.editableTabsValue;
                if (activeName === targetName) {
                    tabs.forEach((tab, index) => {
                        if (tab.id === targetName) {
                            let nextTab = tabs[index + 1] || tabs[index - 1];
                            if (nextTab) {
                                activeName = nextTab.id;
                            }
                        }
                    });
                }
                app.editableTabsValue = activeName;
                app.editableTabs = tabs.filter(tab => tab.id !== targetName);
            }
        }
    });
</script>
</body>
</html>